/*
 * @Author: szx
 * @Date: 2022-05-26 14:05:01
 * @LastEditTime: 2022-05-26 14:16:09
 * @Description:
 * @FilePath: \leetcode\面试题\10\10\10_2.js
 */
var StreamRank = function () {
    this.stack = [];
};

/**
 * @param {number} x
 * @return {void}
 */
StreamRank.prototype.track = function (x) {
    let index = this.getRankOfNumber(x) + 1;
    let i = this.stack.length;
    while (index < len) {
        this.stack[i] = this.stack[i - 1];
        i--;
    }
    this.stack[index] = x;
};

/**
 * @param {number} x
 * @return {number}
 */
StreamRank.prototype.getRankOfNumber = function (x) {
    const stack = this.stack;
    let i = 0,
        j = stack.length - 1;
    while (i <= j) {
        const m = (i + j) >> 1;
        if (stack[m] <= x) i = mid + 1;
        else j = mid - 1;
    }
    return j;
};
StreamRank.prototype.halfSearch = function (x) {
    const stack = this.stack;
    let i = 0,
        j = stack.length - 1;
    while (i <= j) {
        const m = (i + j) >> 1;
        if (stack[m] <= x) i = mid + 1;
        else j = mid - 1;
    }
    return j;
};
